add EmuContractExecutor (sierra-emu backend, interchangeable with AotContractExecutor)#1612
Conversation
|
✅ Code is now correctly formatted. |
b3a574c to
319a6be
Compare
98ed085 to
64c12b3
Compare
319a6be to
92ecf03
Compare
64c12b3 to
7e5fcd7
Compare
92ecf03 to
3b3e5af
Compare
7e5fcd7 to
4176352
Compare
3b3e5af to
24f61ba
Compare
4176352 to
7af0508
Compare
24f61ba to
0ae0d06
Compare
7af0508 to
38c5f2f
Compare
0ae0d06 to
0791b36
Compare
38c5f2f to
81093b3
Compare
0791b36 to
4e80562
Compare
4f53f27 to
6f77130
Compare
4e80562 to
34f9e15
Compare
34f9e15 to
eec22ef
Compare
aa4bf47 to
e6a4ad9
Compare
eec22ef to
487deb9
Compare
538f655 to
c8ed1f7
Compare
701a87c to
61059c1
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: 0 of 23 files reviewed, 1 unresolved discussion (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
-- commits line 1 at r2:
is this missing a rebase?
c8ed1f7 to
90cd01f
Compare
Benchmarking resultsBenchmark for program
|
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
10.644 ± 0.209 | 10.461 | 11.181 | 5.75 ± 0.12 |
cairo-native (embedded AOT) |
1.852 ± 0.015 | 1.825 | 1.869 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.870 ± 0.020 | 1.850 | 1.910 | 1.01 ± 0.01 |
Benchmark for program dict_snapshot
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
515.1 ± 2.2 | 512.9 | 519.3 | 1.00 |
cairo-native (embedded AOT) |
1601.1 ± 11.6 | 1584.5 | 1619.4 | 3.11 ± 0.03 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1632.1 ± 13.5 | 1618.4 | 1661.9 | 3.17 ± 0.03 |
Benchmark for program factorial_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
4.657 ± 0.013 | 4.639 | 4.679 | 2.77 ± 0.03 |
cairo-native (embedded AOT) |
1.682 ± 0.016 | 1.660 | 1.715 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.700 ± 0.023 | 1.677 | 1.747 | 1.01 ± 0.02 |
Benchmark for program fib_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
4.579 ± 0.016 | 4.549 | 4.603 | 2.83 ± 0.03 |
cairo-native (embedded AOT) |
1.619 ± 0.017 | 1.595 | 1.648 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.645 ± 0.011 | 1.630 | 1.667 | 1.02 ± 0.01 |
Benchmark for program linear_search
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
561.3 ± 6.2 | 552.7 | 571.8 | 1.00 |
cairo-native (embedded AOT) |
1637.1 ± 9.4 | 1626.6 | 1653.4 | 2.92 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1673.5 ± 14.7 | 1658.3 | 1703.4 | 2.98 ± 0.04 |
Benchmark for program logistic_map
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
478.7 ± 7.7 | 466.7 | 491.8 | 1.00 |
cairo-native (embedded AOT) |
1606.7 ± 10.2 | 1584.7 | 1621.7 | 3.36 ± 0.06 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1625.1 ± 7.5 | 1615.4 | 1637.5 | 3.39 ± 0.06 |
Benchmark results Main vs HEAD.Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
|
90cd01f to
a1e3635
Compare
Previously, orizi wrote…
Done. |
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 22 files and all commit messages, and made 1 comment.
Reviewable status: 22 of 23 files reviewed, 2 unresolved discussions (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
src/executor/contract_executor.rs line 107 at r3 (raw file):
builtin_stats: Default::default(), }) }
any reason to not just add this into sierra-emu and not need this entire new execute file?
Code quote:
let mut virtual_machine = sierra_emu::VirtualMachine::new_starknet(
Arc::clone(program),
entry_points,
*sierra_version,
);
let emu_builtin_costs = builtin_costs.map(convert_builtin_costs);
virtual_machine.call_contract(selector, gas, args.to_vec(), emu_builtin_costs);
// `VirtualMachine::run` returns `None` when the VM never produced a
// final state -- propagate as an error rather than aborting the host.
let result = virtual_machine.run(&mut syscall_handler).ok_or_else(|| {
Error::UnexpectedValue("sierra-emu VM produced no final state".to_string())
})?;
Ok(ContractExecutionResult {
remaining_gas: result.remaining_gas,
failure_flag: result.failure_flag,
return_values: result.return_values,
error_msg: result.error_msg,
builtin_stats: Default::default(),
})
}|
Previously, orizi wrote…
I removed the ContractExecutor enum and replaced it with a type alias (also removed this file). I looked at the code and at how lambdaclass used it for replay, and there is no dynamic dispatch of Contract executor types. The type used is determined at compile time. So I think we can safely remove this. |
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: 21 of 25 files reviewed, 2 unresolved discussions (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
Previously, avi-starkware (Avi Cohen) wrote…
Done.
are you sure? this seems to contain 4 commits.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 4 files and resolved 1 discussion.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
Mirrors AotContractExecutor::run so the two are interchangeable at call sites. sierra_emu::VirtualMachine::run_contract owns the new_starknet + call_contract + run sequence; this crate only converts BuiltinCosts and the result type at the seam. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4fdd841 to
f62b57a
Compare
avi-starkware
left a comment
There was a problem hiding this comment.
@avi-starkware made 1 comment.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on orizi, TomerStarkware, and Yoni-Starkware).
Previously, orizi wrote…
are you sure? this seems to contain 4 commits.
Done.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware and Yoni-Starkware).
Summary
Makes the sierra-emu interpreter usable as a drop-in alternative to
AotContractExecutorat contract call sites — without a dispatch enum. No consumer selects a backend at runtime (the choice is always made per build by feature flags), so consumers pick an executor type per build instead of wrapping every executor in an enum on the production path.An earlier revision of this PR introduced a
ContractExecutordispatch enum (Aot+Emu); per review it's gone — no consumer, in-tree or out, ever picked a variant at runtime, so the enum'smatchwas ceremony around a decision the build's feature flags had already made.Changes
debug_utils/sierra-emu: newVirtualMachine::run_contract(...)— one-shot convenience overnew_starknet+call_contract+run. ReturnsNonewhen the VM never produced a final state.src/executor/emu_contract_executor.rs(new, gated on the newsierra-emucargo feature):EmuContractExecutor { program, entry_points, sierra_version }with an inherentrun()that mirrorsAotContractExecutor::run— same parameter shape, sameStarknetSyscallHandlertrait (shared viacairo-native-syscalls, so the handler flows through unchanged). ConvertsBuiltinCostsand the emu result into cairo-native'sContractExecutionResult(with defaultbuiltin_stats).Cargo.toml: newsierra-emu = ["dep:sierra-emu"]feature;with-trace-dumpnow depends on the feature rather than the optional dep directly.Stack
run_with_libfunc_profile+AotWithProgramTest plan
cargo check(default features) cleancargo check --features sierra-emucleancargo check --workspace --all-featuresclean (on stack tip)This change is